---
title: Hono
description: Ratelimiting endpoints with Hono
mode: "wide"
---

## Prerequisites

- Created your [Unkey account](https://app.unkey.com/auth/sign-up)
- Created an [Unkey root key](https://app.unkey.com/settings/root-keys) with `ratelimit.*.create_namespace` and `ratelimit.*.limit` permissions.


<Steps titleSize="h3">

<Step title="Create Hono Application">
Run the following command to create your Hono project

<CodeGroup>

```bash npm
npm create hono@latest
```

```bash pnpm
pnpm create hono@latest
```

```bash yarn
yarn create hono@latest
```

```bash bun
bun create hono@latest
```

</CodeGroup>

</Step>
<Step  title="Install">

Now install the `@unkey/ratelimit` package

<CodeGroup>

```bash npm
npm install @unkey/ratelimit
```

```bash pnpm
pnpm add @unkey/ratelimit
```

```bash yarn
yarn add @unkey/ratelimit
```

```bash bun
bun install @unkey/ratelimit
```

</CodeGroup>

</Step>

<Step  title="Add Root Key to env">

Add your root key to your `.env` file

```bash
UNKEY_ROOT_KEY="YOUR_KEY"
```

</Step>

<Step title="Update index to use our Hono SDK">

Create a new route and add the following code

```ts /src/index.ts
import { Hono } from "hono";
import { Ratelimit } from "@unkey/ratelimit";

const app = new Hono();

const limiter = new Ratelimit({
	namespace: "hono-example",
 	limit: 2,
 	duration: "30s",
 	rootKey: process.env.UNKEY_ROOT_KEY
});

app.get("/", (c) => {
  const identifier = getUserId(); // or ip or anything else you want
  const ratelimit = await limiter.limit(identifier)
  if (!ratelimit.success){
   return c.status(429).text("Please try again later")
  }
	return c.text("Hello Hono!");
});

export default app;
```

</Step>

<Step title="Running it">

<CodeGroup>

```bash npm
npm run dev
```

```bash pnpm
pnpm run dev
```

```bash yarn
yarn run dev
```

```bash bun
bun run dev
```

</CodeGroup>

</Step>

<Step  title="Try it out">


```bash
curl -XPOST 'http://localhost:8787/'
```

You will need to curl a few times to see the ratelimiting error. Once you do, you, you will need to wait to perform the action again.


</Step>

</Steps>

## What is next?

Now that you've seen the power of Unkey, check out some resources below to continue your journey.

<CardGroup cols={3}>
  <Card title="Discord" icon="discord" href="https://unkey.com/discord">Join our Discord to chat with us and the community</Card>
  <Card title="Unkey API Reference" icon="database" href="/api-reference">
     Learn about our API that helps you manage APIs, keys, ratelimits and analytical data.
  </Card>
  <Card title="Hono SDK" icon="brackets-curly" href="/libraries/ts/hono">
   Check out our Hono SDK and how they fit into your API.
  </Card>
</CardGroup>
